#ifndef SEQIOT_ASDU_H
#define SEQIOT_ASDU_H

#include <stdint.h>

typedef enum {
    sq_single, sq_sequence
} sequence_e;

typedef struct _variable_struct_qualifier_t {
    uint8_t num: 7; //信息体数量
    sequence_e sq: 1; //是否按顺序排放，0：每个都有单独的ID；1：顺序
}__attribute__((packed)) variable_struct_qualifier_t;

typedef enum _trans_cause_e {
    tc_none = 0,
    tc_percyc = 1,
    tc_back = 2,
    tc_spont = 3,
    tc_init = 4,
    tc_req = 5,
    tc_act = 6,
    tc_actcon = 7,
    tc_deact = 8,
    tc_deactcon = 9,
    tc_actterm = 10,
    tc_reterm = 11,
    tc_retloc = 12,
    tc_file = 13,
    tc_inrngen = 20,
    tc_reqcogen = 37,
    tc_unknown_type_id = 44,
    tc_unknown_cause = 45,
    tc_unknown_rtu = 46,
    tc_unknown_tag_id = 47
} trans_cause_e;

typedef struct _cause_of_transmission_t {
    trans_cause_e cause: 6; //原因
    _Bool pn: 1; //肯定0/否定1 确认
    _Bool test: 1; //测试标志f

    uint8_t lru;
}__attribute__((packed)) cause_of_transmission_t;

typedef struct _data_unit_identifier_t {
    uint8_t type_id; //类型识别符
    variable_struct_qualifier_t vsq; //可变结构图
    cause_of_transmission_t cot; //传输原因
}__attribute__((packed)) asdu_dui_t;

typedef struct {
} channel_session_t;

typedef struct {
    _Bool fcb, fcv;
    trans_cause_e cause;
} device_session_t;

#endif //SEQIOT_ASDU_H
